package org.example.everyday;

import org.slf4j.LoggerFactory;

import java.util.logging.Logger;

/**
 * https://leetcode-cn.com/problems/longest-nice-substring/
 */
public class LongestNiceSubstring {


    public static void main(String[] args) {
        LongestNiceSubstring l = new LongestNiceSubstring();
        String result = l.longestNiceSubstring("YazaAay");
        System.out.println(result);
    }

    public String longestNiceSubstring(String s) {
        int maxLen = 0;
        int maxPos = 0;
        int len = s.length();
        for (int i = 0; i < len; i++) {
            int lower = 0;
            int upper = 0;
            for (int j = i; j < len; j++) {
                if(Character.isLowerCase(s.charAt(j))){
                    lower |= 1 << s.charAt(j) - 'a';
                }else{
                    upper |= 1 << s.charAt(j) - 'A';
                }
                if(lower == upper && j-i+1 > maxLen){
                    maxPos = i;
                    maxLen = j - i + 1;
                    System.out.println("maxPos:"+maxLen+";maxLen:"+maxLen);

                }
            }
        }
        return s.substring(maxPos,maxPos+maxLen);
    }


}
